package com.LeetCode.Math;

import org.junit.Test;

/**
 * 计算二级制字符串
 */
public class CountBit {
    public int countBinarySubstrings(String s) {
        int ptr = 0, n = s.length(), last = 0, ans = 0;
        while(ptr < n){
            char c = s.charAt(ptr);
            int count = 0;
            while(ptr<n && s.charAt(ptr) == c){
                ptr++;
                count++;
            }
            ans += Math.min(count, last);
            last = count;
        }
        return ans;
    }

    @Test
    public void test(){
        System.out.println(countBinarySubstrings("00110011"));
    }

}
